<extend name="Base/common"/>
<block name="Content">
    <form method="post" action="" class="am-form">
        <div class="am-cf am-padding-top">
            <div class="am-fl am-cf">
                <i class="am-icon-file"></i>
                <strong class="am-text-primary am-text-lg">还原数据库</strong>
            </div>
            <hr data-am-widget="divider" class="am-divider am-divider-default" />
        </div>
        <table class="am-table am-table-striped am-table-hover table-main">
            <thead>
                <tr>
                    <th class="table-type am-text-left" style="width:15%">
                        备份名称
                    </th>
                    <th class="table-type am-text-left" style="width:10%">
                        卷数
                    </th>
                    <th class="table-title am-text-left" style="width:10%">
                        压缩
                    </th>
                    <th class="table-set am-text-left" style="width:15%">
                        备份大小
                    </th>
                    <th class="table-set am-text-left" style="width:15%">
                        备份时间
                    </th>
                    <th class="table-set am-text-left" style="width:10%">
                        状态
                    </th>
                    <th class="table-set am-text-left" style="width:20%">
                        操作
                    </th>
                </tr>
            </thead>
            <tbody>
                <notempty name="list">
                    <foreach name="list" item="data">
                        <tr>
                            <td>
                                {$data.time|MyDate='Ymd-His',###}
                            </td>
                            <td>
                                {$data.part}
                            </td>
                            <td>
                                {$data.compress}
                            </td>
                            <td>
                                {$data.size|format_bytes}
                            </td>
                            <td>
                                {$key}
                            </td>
                            <td>
                                -
                            </td>
                            <td>
                                <div class="am-btn-toolbar">
                                    <div class="am-btn-group am-btn-group-xs">
                                        <a class="am-btn am-btn-default am-btn-xs am-text-secondary db-import" href="{:U('import?time='.$data['time'])}">
                                        	<span class="am-icon-undo"></span>
                                        	还原
                                        </a>
                                        <a class="am-btn am-btn-default am-btn-xs am-text-danger ajax-get confirm" href="{:U('del?time='.$data['time'])}">
                                        	<span class="am-icon-trash-o"></span>
                                        	删除
                                        </a>
                                    </div>
                                </div>
                            </td>
                        </tr>
                    </foreach>
                    <else/>
                    <td colspan="7" class="text-center">
                        暂时还没有内容! 
                    </td>
                </notempty>
            </tbody>
        </table>
        <ul class="am-pagination am-pagination-default am-no-layout amz-social">
            {$_page}
        </ul>
    </form>
    </form>
</block>
<block name="script">
    <script type="text/javascript">
        $(".db-import").click(function(){
            var self = this, status = ".";
            $.get(self.href, success, "json");
            window.onbeforeunload = function(){ return "正在还原数据库，请不要关闭！" }
            return false;
        
            function success(data){
                if(data.status){
                    if(data.gz){
                        data.info += status;
                        if(status.length === 5){
                            status = ".";
                        } else {
                            status += ".";
                        }
                    }
                    $(self).closest("td").prev().text(data.info);
                    if(data.part){
                        $.get(self.href, 
                            {"part" : data.part, "start" : data.start}, 
                            success, 
                            "json"
                        );
                    }  else {
                        window.onbeforeunload = function(){ return null; }
                    }
                } else {
                    updateAlert(data.info,'alert-error');
                }
            }
        });
    </script>
</block>